package com.zhongshengnetwork.rightbe.dbservice;

import com.zhongshengnetwork.rightbe.CustomApplication;
import com.zhongshengnetwork.rightbe.dbmodel.LifedbModel;
import com.zhongshengnetwork.rightbe.dbmodel.PicdbModel;
import com.zhongshengnetwork.rightbe.dbmodel.ShopCardbModel;

import org.xutils.DbManager;
import org.xutils.ex.DbException;
import org.xutils.x;

import java.util.List;

/**
 * Created by zhongsheng-luojianlan on 17/3/26.
 */

public class LifedbService {
    //插入或者更新数据
    public static boolean saveOrUpdate(LifedbModel model){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            db.saveOrUpdate(model);
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

    //查找数据
    public static List<LifedbModel> getLifedbModel(){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            if (db.selector(LifedbModel.class) != null){
                List<LifedbModel> list = db.selector(LifedbModel.class).where("userid","==",CustomApplication.loginModel.getUid()).findAll();
                return list;
            }
            return null;
        } catch (DbException e) {
            e.printStackTrace();
            return null;
        }
    }

    //删除数据
    public static boolean deleteByUserid(String userid){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            db.delete(LifedbModel.class,db.selector(LifedbModel.class).where("userid","==",userid).getWhereBuilder());
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }
}
